<?php

namespace app\letterapi\controller;

use app\common\letterbusiness\User as userBn;
use app\common\letterbusiness\Letter as letterBn;
use app\extra\Duiba\Duiba as duibaBn;
class Home extends \app\common\controller\HomeBase {
    /**
     * 首页
     */
    public function index() {
        try {
            $userinfo = $this->_validLogininfo();
            $data['user']=$userinfo;
            $sys = F('System'); 
            $data['note']=$sys['note'];
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 信封列表
     */
    public function letterlist() {
        try {
            $user_id = $this->_validLetterLogin();
            $post['user_id'] = $user_id;
            $data = letterBn::letterList($post);
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }
    /*
     *
    信封信息
     *
     */
    public function letterinfo() {
        try {
            $user_id = $this->_validLetterLogin();
            $post['id'] = input('id');
            $validate = Validate('Letter');
            $post = $validate->scene('letterinfo')->check($post);
            if (!$post) {
                exception($validate->getError(), 10000003);
            }
            $data = letterBn::letterinfo($post,$user_id);
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }
    /*
     *
     分享信封
     *
    */
    public function lettershare() {
        try {
            $user_id = $this->_validLetterLogin();
            $post['id']=input('id');
            $validate = Validate('Letter');
            $post = $validate->scene('letterinfo')->check($post);
            if (!$post) {
                exception($validate->getError(), 10000003);
            }
            $post['user_id']   = $user_id;
            $post['letter_id'] = $post['id'];
            $data = letterBn::lettershare($post,$user_id);
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }
    /*
    *
    分享信封
    *
   */
    public function shareinfo() {
        try {

            $post['id']=input('id');
            $validate = Validate('Letter');
            $post = $validate->scene('letterinfo')->check($post);
            if (!$post) {
                exception($validate->getError(), 10000003);
            }
            $post['id'] = $post['id'];
            $data = letterBn::shareinfo($post);
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }
	    /*
    *
    分享信封
    *
   */
    public function shareinfolist() {
        try { 
            $data = letterBn::shareinfolist($post);
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }


	
    /**
     * 首页分享
     */
    public function shareindex() {
        try {

            $data=array(
                'share_title'=>'一封世界杯来信，一个世界杯回忆',
                'share_img'=>'http://p0.so.qhimgs1.com/bdr/_240_/t0158487d538e404ff4.jpg'
            );
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }
}
